using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using SmartLink.DTOS;
using SmartLink.DTOS.SysBasic;
using SmartLink.Application.IServices;
using SmartLink.Domain;
using SmartLink.DTOS.Permission;
using SmartLink.Infrastructure;
using SmartLink.DTOS.Smart;

namespace SmartLink.WebApi.Controllers
{
    /// <summary>
    /// 系统基础
    /// </summary>
    public class SysBasicController : BaseAPIControl
    {
        private ISysBasicAppServices _sysBasicAppServices;
        public SysBasicController(ISysBasicAppServices sysBasicAppServices)
        {
            _sysBasicAppServices = sysBasicAppServices;
        }

        /// <summary>
        /// 获取字典
        /// </summary>
        [HttpPost]
        public Results<List<DictionaryDTO>> DictionaryList([FromBody]BaseDictionaryDTO model)
        {
            return _sysBasicAppServices.DictionaryList(model.Category);
        }

        /// <summary>
        /// 根据字典类型字符串获取字典内容(参数：1,2,3,4,5)
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Results<Dictionary<string, List<DictionaryDTO>>> ArrayDictionaryList([FromBody] BaseCategorysDTO model)
        {
            return _sysBasicAppServices.ArrayDictionaryList(model.Categorys);
        }

        /// <summary>
        /// 添加字典数据项
        /// </summary>
        /// <param name="model">字典数据模型</param>
        /// <returns></returns>
        public Results AddDictionary(DictionaryDTO model)
        {
            return _sysBasicAppServices.AddDictionary(model, CurUserId);
        }

        /// <summary>
        /// 获取公司树
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        //[HttpPost]
        //public Results<CompanyNode> GetCompanyTree(TreeFlagDTO treeFlagDTO)
        //{
        //    return _sysBasicAppServices.GetCompanyTree(CurUserId, treeFlagDTO);
        //}

        /// <summary>
        /// 获取组织树（包含部门和子公司数据）
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public Results<CompanyNode> GetOrgTree([FromBody]OrgTreePara model)
        {
            if (model.OID == ConstData.SelectAllOptionValue) model.OID = null;
            return _sysBasicAppServices.GetOrgTree(model.OID, model.ToRoot);
        }

        /// <summary>
        /// 获取公司节点树（仅含公司节点）
        /// </summary>
        [HttpPost]
        public Results<CompanyNode> GetCompanyTree([FromBody]OrgTreePara model)
        {
            if (model.OID == ConstData.SelectAllOptionValue) model.OID = null;
            return _sysBasicAppServices.GetCompanyNodeTree(model.OID, model.ToRoot);
        }

        /// <summary>
        /// 获取公司及子公司节点列表（仅含公司节点）
        /// </summary>
        [HttpPost]
        public Results<IList<OrgListItemDTO>> GetCompanyList([FromBody]OrgTreePara model)
        {
            if (model.OID == ConstData.SelectAllOptionValue) model.OID = null;
            return _sysBasicAppServices.GetCompanyNodeList(model.OID, model.ToRoot);
        }

        /// <summary>
        /// 获取部门树
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public Results<CompanyNode> GetDepartmentTree([FromBody]OIDDTO_Nullable model)
        {
            if (model.OID == ConstData.SelectAllOptionValue) model.OID = null;
            return _sysBasicAppServices.GetDepartmentTree(model.OID);
        }

        /// <summary>
        /// 获取当前用户公司节点树（仅含公司节点）
        /// </summary>
        [HttpPost]
        [Obsolete]
        public Results<CompanyNode> GetCurrentCompanyTree()
        {
            return _sysBasicAppServices.GetCompanyNodeTree();
        }

        /// <summary>
        /// 获取当前用户公司节点列表（仅含公司节点）
        /// </summary>
        [HttpPost]
        [Obsolete]
        public Results<IList<OrgListItemDTO>> GetCurrentCompanyList()
        {
            return _sysBasicAppServices.GetCompanyNodeList();
        }

    
        /// <summary>
        /// 获取省市区列表，供省,市,区的选择用
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Results<List<AreaDTO>> GetAreaList()
        {
            return _sysBasicAppServices.GetAreaList();
        }


        /// <summary>
        /// 获取枚举的值的集合
        /// </summary>
        /// <param name="enumKey"></param>
        /// <returns></returns>
        [HttpPost]
        public Results<List<EnumItemDTO>> GetEnumItems(EnumKeyDTO enumKey)
        {
            return _sysBasicAppServices.GetEnumItems(enumKey);
        }

        /// <summary>
        /// 添加系统参数 bom相关
        /// </summary>
        /// <param name="sysParamsDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public Results AddSysParamSettings(SysParamsDTO sysParamsDTO)
        {
            return _sysBasicAppServices.AddSysParamSettings(CurUserId,CurUserInfo.OID,sysParamsDTO);
        }
    }
    
}
